---
title: "Replication"
author: "Silje Synnøve Lyder Hermansen"
date: "2025-07-17"
output: html_document
editor_options: 
  chunk_output_type: console
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
                      warning = FALSE,
                      message = FALSE)
```

# Prepare for analysis

Load in the relevant libraries.
```{r "libraries"}
#Graphics and data wrangling
library(dplyr); library(ggplot2); library(stargazer); library(forcats)

#Hierarchical modeling of outcomes
library(lme4)

#Hurdle models
library(pscl)

#Simulate
library(MASS)

#Fixed-effects model
library(plm)

#Clustered SEs
library(clubSandwich)

```

```{r "set esthetics"}
theme_set(theme_bw())
theme_update(text = element_text(family = "serif"),
             legend.position = "right",
             legend.direction = "vertical",
             legend.title = element_text(face = "bold"),
             axis.text.x = element_text(angle = 45, 
                                        hjust = 1,
                                        size = 12))

```


Load in the four data frames
```{r}
#Role-level data: for analysis of legal capability
load("df_role.rda")

#Applicant-level data: for analysis of winrates
#Carrubba et al.
load("df_app.rda")
#Larsson and Naurin
load("df2_app.rda")


#Case-level data: for analysis of spotlighting and amplifying
load("df_case.rda")

```


# Claim-driven leveling: Individuals win against all odds ($H_1$)

## Table 1

Estimate the models in the main paper (Table 1).
```{r "H1 - Table 1 - estimate the main models"}
#Who submits observations?
mod.obs <- glm(written ~ as.factor(decade_lodged) +
                  individual +
                  ngo +
                  state_institution +              
                  other +
                  role +
                  joined_case,
                df_role,
                family = "binomial")
# Check
# summary(mod.obs)

#How many lawyers?
mod.lawyer <- hurdle(n_lawyers ~  as.factor(decade_lodged) +
                        individual +
                        ngo +
                        state_institution +              
                        other +
                        role +
                        joined_case,
                      df_role)
# Check
# summary(mod.lawyer)

# How experienced is the lawyer?
mod.appear <- hurdle(n_appearances ~ as.factor(decade_lodged) +
                        individual +
                        ngo +
                        state_institution +
                        other +
                        role +
                        joined_case,
                      df_role)
# Check
# summary(mod.appear)
```

Print out the models in the main paper (Table 1)
```{r "H1 - Table 1 - table of results", results='asis'}

variables <- c("Individual (ref. business)",
               "Interest group (ref. business)",
               "State institution (ref. business)",
               "Other (ref. business)",
               "Defendant in main proceedings",
               "Joined cases")

#Period of study
#Earlier period
beg.year <- min(as.numeric(as.character(df_role$year_lodged)))
end.year <- max(as.numeric(as.character(df_role$year_lodged)))

period <- paste(beg.year,"-", end.year,
                 sep = "")

stargazer(mod.obs,
          mod.lawyer, 
          mod.appear,
          covariate.labels = variables,
          dep.var.labels = c("Submitted observation", 
                             "Size of legal team",
                             "Lawyer experience"),
          # column.separate = c(2,2),
          model.numbers = FALSE,
          model.names = TRUE,
          dep.var.caption = c("\\emph{Dependent variable: Quality of legal representation}"),
          font.size = "scriptsize",
          title = "Variation in quality of representation across parties: Companies rely on average on larger and more experienced teams than individual litigants.",
          omit = "decade",
          label = "tab:QoR",
          # out = "Results/Tables/table_QoR.tex",
          type = "html"
          )

```

## Figure 5

### Figure 5a
```{r "Results - QoR - Effect of type on representation - submissions - plot"}
#Set seed
set.seed(9872)

#Empty data frame for figure coordinates
plotData = NULL

#Predictions 

newdata <- matrix(data = 0, 
                  ncol = mod.obs %>% coefficients() %>% length,
                  nrow = 2 )

colnames(newdata) <- mod.obs %>% 
  coefficients() %>%  
  names

#Scenarios

#Baseline (company)
id.sc2 <- grep("Interc|2000", colnames(newdata))
newdata[, id.sc2] = 1

#Individual
id.sc1 <- grep("individual", colnames(newdata))
newdata[1, id.sc1] = 1

sim1 <-mvrnorm(n= 10000, 
               mu= mod.obs$coefficients,
               Sigma= vcov(mod.obs)
               )

xbetas <- newdata %*% t(sim1)
y1  <- exp(xbetas)/(1+exp(xbetas))

newdata <- as.data.frame(newdata)

# Taking quantiles to get point estimate and confidence intervals ##
quantileValues1 <- apply(X = y1, 
                         MARGIN = 1, 
                         FUN = quantile, 
                         na.rm = T, 
                         probs = c(.025,.5,.975))
plotData <- as.data.frame( t(quantileValues1))

# making the plot: 


## Making colours grey scale
color_choice <- c("darkgrey", "black", "azure3", "darkslategrey") #viridis(4)
names(color_choice) <- c("Business", "Individual", "Interest group", "State institution")

plotData$`Type of actor` <- c("Individual",
                              "Business")

plotData <- plotData %>%
  arrange(`Type of actor`)

plotData$x <- c(1,2)


# pdf("Results/Figures/Coefplot_mod_obs.pdf")
ggplot() +
  geom_point(aes(x = x, 
                 y = `50%`,
                 color = `Type of actor`),
             data = plotData,
             size = 3) +
  geom_errorbar(aes(x= x,
                    ymin = `2.5%`,
                    ymax = `97.5%`,
                    color = `Type of actor`),
                data = plotData,
                width = 0) +
  scale_color_manual(values = paste(rep(color_choice[1:2],2))) +
  ggtitle("Probability of a litigant submitting an OBSERVATION") +
  ylim(c(0.7,0.95)) +
  xlim(c(0.8,2.2)) +
  xlab("") +
  ylab("Probability of a submitting an observation") +
  theme(
    plot.title = element_text(size = 18),
    axis.text.x= element_blank(),
        axis.title.y = element_text(size = 16),
        axis.ticks.x = element_blank(),
        # panel.background = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.major.y = element_line(linetype = 2),
        legend.position = "bottom",         
        legend.direction = "horizontal",
        legend.text = element_text(size = 16), 
         #legend.key = element_text( size = 16),
        legend.title = element_text(face = "bold",
                                    size = 16))

# dev.off()

plotData.obs <- plotData

```

### Figure 5b

```{r "Results - QoR - Effect of type on representation - size of team - plot"}
set.seed(9872)

##Earlier period##
n.coef <- sum(grepl("year|decade", names(coefficients(mod.lawyer))) == FALSE)
id.zero.coef <- (grepl("year|decade", names(mod.lawyer$coefficients$zero)) == FALSE)

newdata <- rbind(c(1,1,0,0,0,0,0),
                 c(1,0,0,0,0,0,0))

## calculating the expected count for each simulation*scenario
id2 <- grep("zero",rownames(vcov(mod.lawyer)[id.zero.coef, id.zero.coef]))

sim1 <-mvrnorm(n= 10000, 
               mu= mod.lawyer$coefficients$zero[id.zero.coef],
               Sigma= vcov(mod.lawyer)[id.zero.coef, id.zero.coef][id2, id2])


xbetas <- newdata %*% t(sim1)
y1  <- exp(xbetas)/(1+exp(xbetas))

id2 <- grep("count",rownames(vcov(mod.lawyer)[id.zero.coef, id.zero.coef]))
sim2 <-mvrnorm(n= 10000, 
               mu= mod.lawyer$coefficients$count[id.zero.coef],
               Sigma= vcov(mod.lawyer)[id.zero.coef, id.zero.coef][id2,id2])

xbetas <- newdata %*% t(sim2)
y2  <- exp(xbetas)

expY <- y2 #* y1

newdata <- as.data.frame(newdata)
names(newdata) <- names(coefficients(mod.lawyer))[id.zero.coef][id2]

# Taking quantiles to get point estimate and confidence intervals ##
quantileValues1 <- apply(X = expY, 
                        MARGIN = 1, 
                        FUN = quantile, 
                        probs = c(.025,.5,.975))
plotData <- as.data.frame( t(quantileValues1))

# making the plot: 

plotData$`Type of actor` <- c("Individual",
                              "Business")

plotData <- plotData %>%
  arrange(`Type of actor`)

plotData$x <- c(1,2)


# pdf("Results/Figures/Coefplot_mod_lawyers.pdf")
ggplot() +
  geom_point(aes(x = x, 
                 y = `50%`,
                 color = `Type of actor`),
             data = plotData,
             size = 3) +
  geom_errorbar(aes(x= x,
                    ymin = `2.5%`,
                    ymax = `97.5%`,
                    color = `Type of actor`),
                data = plotData,
                width = 0) +
  scale_color_manual(values = paste(rep(color_choice[1:2],2))) +
  ggtitle("SIZE of LEGAL TEAM conditional on submitting an observation") +
  ylim(c(1,1.5)) +
  xlim(c(0.8,2.2)) +
  xlab("") +
  ylab("Size of legal team") +
  theme(
       plot.title = element_text(size = 18),
       axis.text.x= element_blank(),
        axis.title.y = element_text(size = 16),
        axis.ticks.x = element_blank(),
        # panel.background = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.major.y = element_line(linetype = 2),
        legend.position = "bottom",         
        legend.direction = "horizontal",
        legend.text = element_text(size = 16), 
         #legend.key = element_text( size = 16),
        legend.title = element_text(face = "bold",
                                    size = 16))


# dev.off()

plotData.lawyers <- plotData

```


### Figure 5c

```{r  "Results - QoR - Effect of type on representation - experience - plot"}
set.seed(9872)

##Earlier period##
n.coef <- sum(grepl("decade", names(coefficients(mod.appear))) == FALSE)
id.zero.coef <- (grepl("decade", names(mod.appear$coefficients$zero)) == FALSE)

newdata <- rbind(c(1,1,0,0,0,0,0),
                 c(1,0,0,0,0,0,0))

## calculating the expected count for each simulation*scenario
id2 <- grep("zero",rownames(vcov(mod.appear)[id.zero.coef, id.zero.coef]))

sim1 <-mvrnorm(n= 10000, 
               mu= mod.appear$coefficients$zero[id.zero.coef],
               Sigma= vcov(mod.appear)[id.zero.coef, id.zero.coef][id2, id2])


xbetas <- newdata %*% t(sim1)
y1  <- exp(xbetas)/(1+exp(xbetas))

id2 <- grep("count",rownames(vcov(mod.appear)[id.zero.coef, id.zero.coef]))
sim2 <-mvrnorm(n= 10000, 
               mu= mod.appear$coefficients$count[id.zero.coef],
               Sigma= vcov(mod.appear)[id.zero.coef, id.zero.coef][id2,id2])

xbetas <- newdata %*% t(sim2)
y2  <- exp(xbetas)

expY <- y2 #* y1

newdata <- as.data.frame(newdata)
names(newdata) <- names(coefficients(mod.appear))[id.zero.coef][id2]

# Taking quantiles to get point estimate and confidence intervals ##
quantileValues1 <- apply(X = expY, 
                        MARGIN = 1, 
                        FUN = quantile, 
                        probs = c(.025,.5,.975))
plotData <- as.data.frame( t(quantileValues1))

# making the plot:

plotData$`Type of actor` <- c("Individual",
                              "Business")

plotData <- plotData %>%
  arrange(`Type of actor`)

plotData$x <- c(1,2)

# pdf("Results/Figures/Coefplot_mod_appearances.pdf")
ggplot() +
  geom_point(aes(x = x, 
                 y = `50%`,
                 #shape = period,
                 color = `Type of actor`),
             data = plotData,
             size = 3) +
  geom_errorbar(aes(x= x,
                    ymin = `2.5%`,
                    ymax = `97.5%`,
                    color = `Type of actor`),
                data = plotData,
                width = 0) +
  scale_color_manual(values = paste(rep(color_choice[1:2],2))) +
  ggtitle("Lawyer EXPERIENCE conditional on submitting an observation") +
  # ylim(c(0,3)) +
  xlim(c(0.8,2.2)) +
  xlab("") +
  ylab("Number of appearances before the ECJ") +
    theme(
       plot.title = element_text(size = 18),
       axis.text.x= element_blank(),
        axis.title.y = element_text(size = 16),
        axis.ticks.x = element_blank(),
        # panel.background = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.major.y = element_line(linetype = 2),
        legend.position = "bottom",         
        legend.direction = "horizontal",
        legend.text = element_text(size = 16), 
         #legend.key = element_text( size = 16),
        legend.title = element_text(face = "bold",
                                    size = 16))


# dev.off()

plotData.appearances <- plotData

```


# Win rates 

## Figure 6: Barplot over individual rights
```{r}
#Load data frame on subject matter initially from from EurLex

load("SubjectMatter.rda")

inds <- 
  df_app %>%
  filter(
    individual == 1
  ) 

ind_subj <- inner_join(SubjectMatter,
                  inds %>% dplyr::select(celex, individual, ind_rights) %>% distinct(celex, .keep_all = T),
                  by = "celex")

ind_subj <- 
  ind_subj %>%
  #Recode and merge
  mutate(
    subject = if_else(grepl("Social Policy", subject), 
                      "Social policy",
                      subject),
    subject = if_else(grepl("Staff regulations and employment conditions", subject), 
                      "Staff regulations and employment conditions",
                      subject),
    subject = if_else(grepl("Agriculture and Fisheries", subject), "Agriculture and fisheries",
                           subject),
         subject = if_else(grepl("Beef and veal|Wine|Cereals|Sheepmeat|Sugar|Milk products|Pigmeat|Fruit and v|Eggs and poul|Fisheries policy", subject),
                           "Agriculture and fisheries",
                           subject),
         subject = if_else(grepl("Approximation of laws", subject), NA, subject)
         ) %>%
  filter(!is.na(subject)) %>%
  distinct(., .keep_all = T) %>%
  mutate(
    subject = if_else(grepl("Brussels Convention", subject), "Brussels Convention", subject)
  ) 

##Create the plot##

# pdf("Results/Figures/Barplot_individual_rights.pdf")
ind_subj %>%
  group_by(subject) %>%
  mutate(n = n()) %>%
  ungroup() %>%
  mutate(
         "Rights-claim by individual" = if_else(ind_rights == 1, 
                                                "Individual right", 
                                                "Other topics"),
         subject = fct_reorder(subject, n)) %>%
  filter(n >= 10) %>%
  ggplot +
  geom_bar(
    aes(
      y = subject,
      # fill = `Rights-claim by individual`
    )) +
  scale_fill_manual(values = c("Individual right" = "black", 
                               "Other topics" = "gray")) +
  ylab("") + 
  xlab("Number of cases") +
  theme(
    legend.direction = "horizontal",
    legend.position = "bottom"
  ) +
  ggtitle("What do individual applicants litigate on?",
          subtitle = "Preliminary references in which individuals were involved (1961-2007)")

# dev.off()

```



## Table 2: Models on win rate

Merge and prepare the data from the two periods/coding projects.
```{r "merge and prepare data from the two periods"}

df_app$n_lawyers[df_app$n_lawyers > 5] = 5
df_app$n_lawyers_def[df_app$n_lawyers_def > 5] = 5

df_app$n_appearances[df_app$n_appearances > 25] = 25
df_app$n_appearances_def[df_app$n_appearances_def > 25] = 25

df2_app$n_lawyers[df2_app$n_lawyers > 5] = 5
df2_app$n_lawyers_def[df2_app$n_lawyers_def > 5] = 5

df2_app$n_appearances[df2_app$n_appearances > 25] = 25
df2_app$n_appearances_def[df2_app$n_appearances_def > 25] = 25


#Truncate iteration
df_app$n_iteration_trunc <- df_app$n_iteration
#Assign a group of NAs
df_app$n_iteration_trunc[is.na(df_app$n_iteration)] = 0
df_app$n_iteration_trunc[df_app$n_iteration_trunc > 100] = round(df_app$n_iteration_trunc[df_app$n_iteration_trunc > 100], -1) 

df2_app$n_iteration_trunc <- df2_app$n_iteration
df2_app$n_iteration_trunc[is.na(df2_app$n_iteration)] = 0
df2_app$n_iteration_trunc[df2_app$n_iteration_trunc > 100] = round(df2_app$n_iteration_trunc[df2_app$n_iteration_trunc > 100], -1) 


# Does the applicant win?
#Create weights to account for nesting
df_app <- 
  df_app %>%
  filter(!is.na(win)) %>%
  group_by(celex) %>%
  mutate(n_issues = n()) %>%
  dplyr::select(win, n_issues, individual,
                company,
         ngo, state_institution, other,
         govobspl, govobsdef, 
         n_iteration, n_iteration_trunc,
         challenge, 
         company_def, individual_def, other_def,
         ngo_def, n_lawyers, n_lawyers_def,
         state_institution_def,
         n_appearances, n_appearances_def,
         ind_rights, year_lodged) %>%
  na.omit()

df2_app <- 
  df2_app %>%
  filter(!is.na(win)) %>%
  group_by(celex) %>%
  mutate(n_issues = n()) %>%
  dplyr::select(win, n_issues, individual,
                company,
         ngo, state_institution, other,
         govobspl, govobsdef, 
         n_iteration, n_iteration_trunc,
         challenge, 
         company_def, individual_def, other_def,
         ngo_def, n_lawyers, n_lawyers_def,
         state_institution_def,
         n_appearances, n_appearances_def,
         ind_rights, year_lodged) %>%
  na.omit()

df_app_merged <- rbind(
  cbind(df_app, source = "CH"),
  cbind(df2_app, source = "LN")
)

#Filter out the Larsson and Naurin cases covered by Carrubba and Hankla
celex_overlap <- 
  df_app_merged %>%
  group_by(celex) %>%
  reframe(n = length(unique(source))) %>%
  filter(n > 1)

df_app_merged <- 
  df_app_merged %>%
  filter(!(celex %in% celex_overlap$celex &
           source == "CH"))

```


```{r "table 2a - estimate the models on win rates"}
#The rights argument individual win-rate in individual rights cases#
mod.win.rights <- plm(win ~ 
                     individuals_claiming_rights +
                     individual +
                     ngo +
                     state_institution +
                     other +
                     I(govobspl - govobsdef) +
                     # I(n_iteration == 1) +
                     # log(n_iteration) +
                     challenge +
                     individual_def +
                     ngo_def +
                     state_institution_def +
                     other_def +
                     I(n_lawyers - n_lawyers_def) +
                     I(n_appearances - n_appearances_def) +
                     source,
                   effect = "individual",
                   index = "n_iteration",
                   #    family = "binomial",
                   weights = 1/n_issues,
                   # na.action = "na.exclude",
                   df_app_merged %>%
                     mutate(
                       individual = as.numeric(individual),
                       individuals_claiming_rights = if_else(individual == 1 &
                                                               ind_rights == 1,
                                                             1, 0)
                     ))

## Check
# summary(mod.win.rights)
#Custered errors
mod.win.rights.se <- coef_test(mod.win.rights, 
                           vcovCR(mod.win.rights,
                                  cluster = df_app_merged$celex,
                                  type = "CR1p"),
                           test = "naive-t")


```


```{r "table 2b - estimate the models on win rates"}
##==============##
##Both data sets##
##==============##

#Individual win rate
mod.win <- plm(win ~ 
                    individual +
                    ngo +
                    state_institution +
                    other +
                    I(govobspl - govobsdef) +
                    # I(n_iteration == 1) +
                   # log(n_iteration) +
                    challenge +
                    individual_def +
                    ngo_def +
                    state_institution_def +
                    other_def +
                    I(n_lawyers - n_lawyers_def) +
                    I(n_appearances - n_appearances_def) +
                  source,
                  effect = "individual",
                  index = "n_iteration",
              #    family = "binomial",
                  weights = 1/n_issues,
                  # na.action = "na.exclude",
                  df_app_merged %>%
                mutate(
                  individual = as.numeric(individual)
                ))

## Check
# summary(mod.win)

#Custered errors
mod.win.se <- coef_test(mod.win, 
                           vcovCR(mod.win,
                                  cluster = df_app_merged$celex,
                                  type = "CR1p"),
                           test = "naive-t")

```

```{r "table 2c - estimate the models on win rates"}
#Only the first time the case is brought
mod.win.rights1 <- lm(win ~ 
                        individuals_claiming_rights +
                        individual +
                        ngo +
                        state_institution +
                        other +
                        I(govobspl - govobsdef) +
                        # I(n_iteration == 1) +
                        # log(n_iteration) +
                        challenge +
                        individual_def +
                        ngo_def +
                        state_institution_def +
                        other_def +
                        I(n_lawyers - n_lawyers_def) +
                        I(n_appearances - n_appearances_def) +
                       # n_iteration
                      +  source,
                      # effect = "individual",
                      # index = "n_iteration",
                      #    family = "binomial",
                      weights = 1/n_issues,
                      # na.action = "na.exclude",
                      df_app_merged %>%
                       filter(
                         n_iteration == 1
                       ) %>%
                        mutate(
                          individual = as.numeric(individual),
                          individuals_claiming_rights = if_else(individual == 1 &
                                                                  ind_rights == 1,
                                                                1, 0)
                        ))

## Check
# summary(mod.win.rights1)

#Clustered errors
mod.win.rights1.se <- coef_test(mod.win.rights1, 
                               vcovCR(mod.win.rights1,
                                      cluster = df_app_merged$celex[df_app_merged$n_iteration == 1],
                                      type = "CR1p"),
                               test = "naive-t")


```


```{r "table 2 - make the table", results = "asis"}

period.ch <- paste(min(df_app$year_lodged, na.rm = T),
                   "-",
                   max(df_app$year_lodged, na.rm = T),
                 sep = "")
period.ln <- paste(min(df2_app$year_lodged, na.rm = T),
                   "-",
                   max(df2_app$year_lodged, na.rm = T),
                 sep = "")


##Both data sets merged: with rights claims

variables <- c("Rights-claim by individual",
               "Individual (ref. business)",
               "Interest group (ref. business)",
               "State institution (ref. business)",
               "Other (ref. business)",
               "Net support from MS observations",
               "The validity of an EU law is in question",
               "Defendant is ... an individual (ref. business)",
               "... interest group (ref. business)",
               "... state institution (ref. business)",
               "... other type of actor (ref. business)",
               "Difference in legal team size",
               "Difference in lawyer experience",
               "Source",
               "Constant")

stargazer(mod.win.rights, mod.win, mod.win.rights1,
          se = list(
            mod.win.rights.se$SE,
            mod.win$SE,
            mod.win.rights1.se$SE
                    ),
          covariate.labels = variables,
          column.labels = c("indivdual rights", "individuals",
                            "individual rights"),
          dep.var.labels = c("Wins the case"),
          # column.separate = c(2,2),
          model.numbers = FALSE,
          model.names = TRUE,
          font.size = "scriptsize",
          omit.stat = "f",
          title = "Variation in the likelihood of winning among applicants accross types of litigants.",
          omit = "decade",
          label = "tab:win",
          add.lines = list(c("Fixed effects for iteration of interpretation", "Yes", "Yes", "No")),
          # out = "Results/Tables/table_win.tex",
          type = "html")

```

## Figure 7

```{r "figure 7 - reestimate the model and make the figure"}
#The rights argument individual win-rate in individual rights cases: reestimate with state institution as reference point to get the predictions for companies#

mod.win.rights.plot <- plm(win ~ 
                        company +
                        individuals_claiming_rights +
                        individual +
                        ngo +
                        # state_institution +
                        other +
                        I(govobspl - govobsdef) +
                        # I(n_iteration == 1) +
                        # log(n_iteration) +
                        challenge +
                        individual_def +
                        ngo_def +
                        state_institution_def +
                        other_def +
                        I(n_lawyers - n_lawyers_def) +
                        I(n_appearances - n_appearances_def) +
                        source,
                      effect = "individual",
                      index = "n_iteration",
                      #    family = "binomial",
                      weights = 1/n_issues,
                      # na.action = "na.exclude",
                      df_app_merged %>%
                        mutate(
                          individual = as.numeric(individual),
                          individuals_claiming_rights = if_else(individual == 1 &
                                                                  ind_rights == 1,
                                                             1, 0)
                     ))
##Check
# summary(mod.win.rights.plot)

#Custered errors
mod.win.rights.plot.se <- coef_test(mod.win.rights.plot, 
                           vcovCR(mod.win.rights.plot,
                                  cluster = df_app_merged$celex,
                                  type = "CR1p"),
                           test = "naive-t")


set.seed(1234)

##The 1st and 3rd models including ind vs. companies
plotData = NULL

#Predictions 

newdata <- matrix(data = 0, 
                  ncol = mod.win.rights.plot %>% coefficients() %>% length,
                  nrow = 3 )

colnames(newdata) <- mod.win.rights.plot %>% 
  coefficients() %>%  
  names

#Scenarios

# #Baseline (company)
# id.sc2 <- grep("Interc", colnames(newdata))
# newdata[, id.sc2] = 1

#Individual
id.sc1 <- grep("individual", colnames(newdata))[1:2]
newdata[1, id.sc1] = 1

id.sc1 <- grep("individual", colnames(newdata))[2]
newdata[2, id.sc1] = 1

id.sc1 <- grep("company", colnames(newdata))[1]
newdata[3, id.sc1] = 1


sim1 <-mvrnorm(n= 10000, 
               mu= mod.win.rights.plot$coefficients,
               Sigma = vcovCR(mod.win.rights.plot, 
                              cluster = df_app_merged$celex, 
                              type = "CR1p")
#               Sigma= vcov(mod.win.ch)
               )
xbetas <- newdata %*% t(sim1)

#Add intercept (1st time a law comes around)
y1 <- xbetas + fixef(mod.win.rights.plot)[1]  #exp(xbetas)/(1 + exp(xbetas))


# Taking quantiles to get point estimate and confidence intervals ##
quantileValues1 <- apply(X = y1, 
                         MARGIN = 1, 
                         FUN = quantile, 
                         na.rm = T, 
                         probs = c(.025,.5,.975))


plotData <- t(quantileValues1) %>%
  as.data.frame()

plotData$`Type of actor` <- c(
  "Individual rights",
  "Individual",
  "Business")


plotData <- plotData %>%
  arrange(`Type of actor`)

plotData$x <- c(1,
                2,
                3)




# pdf("Results/Figures/Coefplot_mod_win_rights.pdf")
ggplot() +
  geom_point(aes(x = `Type of actor`, 
                 y = `50%`),
             data = plotData,
                 size = 3) +
  geom_errorbar(aes(x = `Type of actor`,
                    ymin = `2.5%`,
                    ymax = `97.5%`),
                data = plotData,
                width = 0) +
  # scale_color_manual(values = paste(color_choice[c(1,2)])) +
  ggtitle("Probability of WINNING the case") +
  # ylim(c(0,3)) +
  # xlim(c(0.8,2.2)) +
  # scale_x_continuous(breaks=c(1, 2),
  #                    labels=c("Business\n(non-ind. rights cases)", "Individual\n(ind. rights cases)")) +
  xlab("") +
  ylab("Prob. of winning") +
     theme(
       plot.title = element_text(size = 18),
       axis.text.x= element_text(angle = 0, hjust = 0.5),
        axis.title.y = element_text(size = 16),
        axis.ticks.x = element_blank(),
        # panel.background = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.major.y = element_line(linetype = 2),
        legend.position = "bottom",         
        legend.direction = "horizontal",
        legend.text = element_text(size = 16), 
         #legend.key = element_text( size = 16),
        legend.title = element_text(face = "bold",
                                    size = 16))



# dev.off()

plotData.win <- plotData

```


# Spotlighting \& Amplifying ($H_2$): Broadcasting Decisions Where Individuals Win

## Table 3

```{r "recode the case level data and prepare for analysis"}
df_case$decade_lodged <- as.numeric(gsub(".$*", "0", df_case$year_lodged))
df_case$decade_lodged <- as.factor(df_case$decade_lodged) %>% 
  relevel(ref = "2000")

#Member state observations
#Period 2
df_case$individual <- as.numeric(df_case$individual)
df_case$ngo <- as.numeric(df_case$ngo)
df_case$state_institution <- as.numeric(df_case$state_institution)
df_case$other <- as.numeric(df_case$other)

df_case$obs_applicant <- df_case$written_applicant
df_case$obs_defendant <- df_case$written_defendant

```


```{r "table 3a - chamber size - ordinal regression - estimate model"}
#Chamber size
mod.ch <- polr(chamber_size ~
                 individual +
                 ngo +
                 state_institution +
                 other +
                  log(n_lawyers_applicant + 1) +
                  log(n_lawyers_defendant + 1) +
                  log(n_appearances_applicant + 1) +
                  log(n_appearances_defendant + 1) +
                 log(n_iteration) +
                 observations_prop_tot +
                as.factor(decade_lodged),
               df_case,
               Hess = T
               )
```

```{r "table 3b - press release - binomial logistic regression - estimate model"}
mod.press <-  glm(press_release ~ 
                    individual +
                    ngo +
                    state_institution +
                    other +
                    log(n_lawyers_applicant + 1) +
                    log(n_lawyers_defendant + 1) +
                    log(n_appearances_applicant + 1) +
                    log(n_appearances_defendant + 1) +
                    log(n_iteration) +
                    observations_prop_tot +
                    as.factor(decade_lodged), 
                  df_case, 
                  subset = !is.na(press_release) & !is.na(win),
                  family = "binomial")

```

```{r  "table 3c - legal annotations - negative binomial regression - estimate model"}
#Annotations
mod.ann <- glm.nb(n_annotations ~
                 individual +
                 ngo +
                 state_institution +
                 other +
                  # obs_applicant +
                  # obs_defendant +
                  log(n_lawyers_applicant + 1) +
                  log(n_lawyers_defendant + 1) +
                  log(n_appearances_applicant + 1) +
                  log(n_appearances_defendant + 1) +
                 log(n_iteration) +
                 observations_prop_tot +
                as.factor(decade_lodged)+
                  as.factor(origin),
               df_case#,
               # family = "poisson"
               )

```

```{r "table 3d - annotaed in the CMLR - binomial logistic regression - estimate model"}
#Annotations in the CMLR
mod.cmlr <- glm((n_annotations_CMLR>0) ~
                  individual +
                  ngo +
                  state_institution +
                  other +
                  # obs_applicant +
                  # obs_defendant +
                  log(n_lawyers_applicant + 1) +
                  log(n_lawyers_defendant + 1) +
                  log(n_appearances_applicant + 1) +
                  log(n_appearances_defendant + 1) +
                 log(n_iteration) +
                 observations_prop_tot +
                  as.factor(decade_lodged),
               df_case,
               family = "binomial"
               )
```


```{r "table 3 - attention", results = "asis"}

variables.attention <- c("Applicant is... an individual (ref. business)",
                         "... interest group (ref. business)",
                         "... state institution (ref. business)",
                         "... other type of actor (ref. business)",
                         "Size of applicant's legal team (log + 1)",
                         "Size of defendant's legal team (log + 1)",
                         "Experience of applicant's lawyer (log + 1)",
                         "Experience of defendant's lawyer (log + 1)",
                         "Times an EU law is applied (log)",
                         "Proportion of MS observations",
                         "Small|medium chamber",
                         "Medium|Large chamber",
                         "Intercept")
 
##Table for main text##
stargazer(mod.ch, mod.press, mod.ann, mod.cmlr,
          covariate.labels = variables.attention,
          column.labels = c("1961-2016",
                            "1995-2016",
                            "1961-2016",
                            "1961-2016"),          
          dep.var.labels = c( "Chamber size", 
                              "Press release",
                             "Case annotations",
                             "CMLR annotation"),
          dep.var.labels.include = TRUE,
          model.numbers = FALSE,
          model.names = TRUE,
          dep.var.caption = c("\\emph{Dependent variable: Judicial and academic attention}"),
          add.lines = list(
                           c("Decade fixed effects", "Yes", "Yes", "Yes", "Yes"),
                           c("Country of origin fixed effects", "No", "No", "Yes", "No")),
          ord.intercepts = TRUE,
          title = "Spotlighting and amplifying: Judicial and academic issue attention depend on the type of litigants involved.",
          omit = "decade|EUsize|origin",
          keep.stat = "n",
          font.size = "tiny",
          label = "tab:attention",
          # out = "Results/Tables/table_attention.tex",
          type = "html")

```


## Table 4

```{r "table 4 - estimate the models"}
df_case$individual_applicant <- as.numeric(df_case$individual_applicant)

mod.press.win <- glm(press_release ~
                       log(n_iteration) +
                       observations_prop_tot +
                       as.factor(year_lodged) +
                       win * other_applicant +
                       win * state_institution_applicant  +
                       win * ngo_applicant +
                       win * individual_applicant ,
                     subset = !is.na(win) & !is.na(press_release),
                     family = "binomial",
                     data = df_case)
# summary(mod.press.win)

mod.ann.win <- glm.nb(n_annotations ~
                     log(n_iteration) +
                     observations_prop_tot +
                     as.factor(decade_lodged ) +
                       as.factor(origin) +
                     # win_source +
                     win * other_applicant +
                     win * state_institution_applicant +
                     win * ngo_applicant+
                     win * individual_applicant ,
                   subset = !is.na(win),
                   # family = "poisson",
                   data = df_case)

# summary(mod.ann.win)

mod.cmlr.win <- glm((n_annotations_CMLR > 0) ~
                      log(n_iteration) +
                      observations_prop_tot +
                      as.factor(decade_lodged ) +
                      # win_source +
                      win * other_applicant  +
                      win * state_institution_applicant +
                      win * ngo_applicant +
                      win * individual_applicant ,
                    subset = !is.na(win),
                    family = "binomial",
                    data = df_case)

```


```{r "table 4 - make the table of results", results = "asis"}
variables.win <- c("Times an EU law is applied (log)",
                   "Proportion of MS observations",
                   "Applicant won",
                   "Applicant is... other type of actor (ref. business)",
                   "... state institution (ref. business)",
                   "... interest group (ref. business)",
                   "... an individual (ref. business)",
                   "Applicant won * other type of actor (ref. business)",
                   "... won * state institution (ref. business)",
                   "... won * interest group (ref. business)",
                   "... won * an individual (ref. business) (H3)", 
                   "Intercept")
##Main table 
stargazer(mod.press.win, 
          mod.ann.win, 
          mod.cmlr.win,
          covariate.labels = variables.win,
          column.labels = c("1997-2008", 
                            "1961-2008", 
                            "1961-2008"), 
          dep.var.labels = c("Press release", 
                             "Case annotations",
                             "Annotated in CMLR"),
          dep.var.labels.include = TRUE,
          model.numbers = FALSE,
          model.names = TRUE,
          dep.var.caption = c("\\emph{Dependent variables: Spotlighting and amplifying}"),
          title = "Spotlighting and amplifying: Issue attention as a function of whether the individual applicant wins.",
          omit = "year|decade|origin",          
          add.lines = list(c("Decade fixed effects", "Yes",  "Yes", "Yes"),
                           c("Country of origin fixed effects", "No",  "No", "Yes")),
          keep.stat = "n",
          font.size = "scriptsize",
          label = "tab:attention_win",
          # out = "Results/Tables/table_attention_win.tex",
          type = "html")
```


## Figure 8

### Figure 8a
```{r "figure 8a - chamber size"}
set.seed(9872)

plotData = NULL

#Predictions 

newdata <- matrix(data = 0, 
                  ncol = mod.ch %>% coefficients() %>% length +
                    mod.ch$zeta %>% length,
                  nrow = 2 )

colnames(newdata) <- c(mod.ch %>% 
                         coefficients() %>%  
                         names,
                       mod.ch$zeta %>% 
                         names
                       )

#Scenarios

#Baseline (company)
id.sc2 <- grep("2000|large", colnames(newdata)) #Intercept = probability of passing from medium to large
newdata[, id.sc2] = 1
id.sc2 <- grep("lawy", colnames(newdata))
newdata[, id.sc2] = log(1+1)
id.sc2 <- grep("obser", colnames(newdata))
newdata[, id.sc2] = 2/25

#Individual
id.sc1 <- grep("indiv", colnames(newdata))
newdata[1, id.sc1] = 1

#Simulate coefficients for errors
sim1 <- mvrnorm(n= 10000, 
               mu= append(mod.ch$coefficients, #Ordered logits intercept - beta
                          mod.ch$zeta), #Intercepts
               Sigma= vcov(mod.ch))



xbetas <- newdata[,1:(ncol(newdata)-2)] %*% t(sim1[,1:(ncol(newdata)-2)])
theta <- newdata[,(ncol(newdata)-1):ncol(newdata)] %*% t(sim1[,(ncol(newdata)-1):ncol(newdata)])

xbetas <- theta - xbetas

# xbetas <- newdata %*% t(sim1)
y1  <- exp(xbetas)/(1 + exp(xbetas))
y1 <- 1 - y1

# Taking quantiles to get point estimate and confidence intervals ##
quantileValues1 <- apply(X = y1, 
                         MARGIN = 1, 
                         FUN = quantile, 
                         na.rm = T, 
                         probs = c(.025,.5,.975)
                         )
plotData <- as.data.frame( t(quantileValues1))



# making the plot:

plotData$`Type of actor` <- c("Individual",
                              "Business")

plotData <- plotData %>%
  arrange(`Type of actor`)

plotData$x <- c(1, 2)

# pdf("Results/Figures/Coefplot_mod_chamber.pdf")
ggplot() +
  geom_point(aes(x = x, 
                 y = `50%`,
                    color = `Type of actor`),
             data = plotData,
                 size = 3) +
  geom_errorbar(aes(x= x,
                    ymin = `2.5%`,
                    ymax = `97.5%`,
                    color = `Type of actor`),
                data = plotData,
                width = 0) +
  scale_color_manual(values = paste(rep(color_choice[1:2],2))) +
  ggtitle("SPOTLIGHTING: Court's choice of CHAMBER SIZE \nby type of litigant") +
  # ylim(c(0.5,1)) +
  xlim(c(0.8,2.2)) +
  xlab("") +
  ylab("Probability of a large chamber") +
     theme(
       plot.title = element_text(size = 18),
       axis.text.x= element_blank(),
        axis.title.y = element_text(size = 16),
        axis.ticks.x = element_blank(),
        # panel.background = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.major.y = element_line(linetype = 2),
        legend.position = "bottom",         
        legend.direction = "horizontal",
        legend.text = element_text(size = 16), 
         #legend.key = element_text( size = 16),
        legend.title = element_text(face = "bold",
                                    size = 16))
  
  

# dev.off()

plotData.ch <- plotData
```

### Figure 8b
```{r "figure 8a - press release"}
set.seed(9872)

plotData = NULL

#Predictions 

newdata <- matrix(data = 0, 
                  ncol = mod.press %>% coefficients() %>% length,
                  nrow = 2 )

colnames(newdata) <- mod.press %>% 
  coefficients() %>%  
  names

#Scenarios

#Baseline (company)
id.sc2 <- grep("Interc", colnames(newdata))
newdata[, id.sc2] = 1

#Individual
id.sc1 <- grep("indiv", colnames(newdata))
newdata[1, id.sc1] = 1

#Iteration
id.sc1 <- grep("observations", colnames(newdata))
newdata[, id.sc1] = 2/25

sim1 <-mvrnorm(n= 10000, 
               mu= mod.press$coefficients,
               Sigma= vcov(mod.press)
               )
xbetas <- newdata %*% t(sim1)
y1  <- exp(xbetas)/(1 + exp(xbetas))

newdata <- as.data.frame(newdata)

# Taking quantiles to get point estimate and confidence intervals ##
quantileValues1 <- apply(X = y1, 
                         MARGIN = 1, 
                         FUN = quantile, 
                         na.rm = T, 
                         probs = c(.025,.5,.975))
plotData <- as.data.frame(t(quantileValues1)) 
  

# making the plot:

plotData$`Type of actor` <- c("Individual",
                              "Business")

plotData <- plotData %>%
  arrange(`Type of actor`)

plotData$x <- c(1, 2)


# pdf("Results/Figures/Coefplot_mod_press.pdf")
ggplot() +
  geom_point(aes(x = x, 
                 y = `50%`,
                 color = `Type of actor`),
             data = plotData,
                 size = 3) +
  geom_errorbar(aes(x= x,
                    ymin = `2.5%`,
                    ymax = `97.5%`,
                    color =  `Type of actor`),
                data = plotData,
                width = 0) +
  scale_color_manual(values = paste(color_choice[1:2])) +
  ggtitle("SPOTLIGHTING:Court's decision to issue a PRESS RELEASE\nby type of litigant") +
  ylim(c(0,0.4)) +
  # scale_x_continuous(breaks=c(1, 2),
  #                    labels=c("Company", 
  #                             "Individual")) +
  coord_cartesian(xlim = c(0.8,2.2)) +
  xlab("") +
  ylab("Probability of press release") +
     theme(
       plot.title = element_text(size = 18),
       axis.text.x= element_blank(), #element_text(angle = 0, hjust = 0.5),
        axis.title.y = element_text(size = 16),
        axis.ticks.x = element_blank(),
       axis.line.x = element_blank(),
        # panel.background = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.major.y = element_line(linetype = 2),
        legend.position = "bottom",         
        legend.direction = "horizontal",
        legend.text = element_text(size = 16), 
         #legend.key = element_text( size = 16),
        legend.title = element_text(face = "bold",
                                    size = 16))

# dev.off()

plotData.press <- plotData
```

### Figure 8c

```{r "figure 8c - annotations"}
set.seed(9872)

plotData = NULL

#Predictions 

newdata <- matrix(data = 0, 
                  ncol = mod.ann %>% coefficients() %>% length,
                  nrow = 2 )

colnames(newdata) <- mod.ann %>% 
  coefficients() %>%  
  names

#Scenarios

#Baseline (company)
id.sc2 <- grep("Interc|2000|state", colnames(newdata))
newdata[, id.sc2] = 1

id.sc2 <- grep("lawyer", colnames(newdata))
newdata[, id.sc2] = log(1+1)

id.sc2 <- grep("observ", colnames(newdata))
newdata[, id.sc2] = 2/25

#Individual
id.sc1 <- grep("indiv", colnames(newdata))
newdata[1, id.sc1] = 1

sim1 <-mvrnorm(n= 10000, 
               mu= mod.ann$coefficients,
               Sigma= vcov(mod.ann)
               )
xbetas <- newdata %*% t(sim1)
y1  <- exp(xbetas)

newdata <- as.data.frame(newdata)

# Taking quantiles to get point estimate and confidence intervals ##
quantileValues1 <- apply(X = y1, 
                         MARGIN = 1, 
                         FUN = quantile, 
                         na.rm = T, 
                         probs = c(.025,.5,.975))
plotData <- as.data.frame( t(quantileValues1))

# making the plot: 

plotData$`Type of actor` <- c("Individual",
                              "Business")

plotData <- plotData %>%
  arrange(`Type of actor`)

plotData$x <- c(1,2)

# pdf("Results/Figures/Coefplot_mod_ann.pdf")
ggplot() +
  geom_point(aes(x = x, 
                 y = `50%`,
                 color = `Type of actor`),
             data = plotData,
             size = 3) +
  geom_errorbar(aes(x= x,
                    ymin = `2.5%`,
                    ymax = `97.5%`,
                 color = `Type of actor`),
                data = plotData,
                width = 0) +
  scale_color_manual(values = paste(rep(color_choice[1:2],2))) +
  ggtitle("AMPLIFYING: Publications in LEGAL JOURNALS\nby type of litigant") +
  # ylim(c(0,0.2)) +
  xlim(c(0.8,2.2)) +
  xlab("") +
  ylab("Number of annotations") +
     theme(
       plot.title = element_text(size = 18),
       axis.text.x= element_blank(),
        axis.title.y = element_text(size = 16),
        axis.ticks.x = element_blank(),
        # panel.background = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.major.y = element_line(linetype = 2),
        legend.position = "bottom",         
        legend.direction = "horizontal",
        legend.text = element_text(size = 16), 
         #legend.key = element_text( size = 16),
        legend.title = element_text(face = "bold",
                                    size = 16))


# dev.off()

plotData.ann <- plotData
```


### Figure 8d
```{r "figure 8d - annotations in the CMLR"}
set.seed(9872)

plotData = NULL

#Predictions 

newdata <- matrix(data = 0, 
                  ncol = mod.cmlr %>% coefficients() %>% length,
                  nrow = 2 )

colnames(newdata) <- mod.cmlr %>% 
  coefficients() %>%  
  names

#Scenarios

#Baseline (company)
id.sc2 <- grep("Interc|2000|state", colnames(newdata))
newdata[, id.sc2] = 1

id.sc2 <- grep("lawyer", colnames(newdata))
newdata[, id.sc2] = log(1+1)

id.sc2 <- grep("observ", colnames(newdata))
newdata[, id.sc2] = 2/25

#Individual
id.sc1 <- grep("indiv", colnames(newdata))
newdata[1, id.sc1] = 1

sim1 <-mvrnorm(n= 10000, 
               mu= mod.cmlr$coefficients,
               Sigma= vcov(mod.cmlr)
               )
xbetas <- newdata %*% t(sim1)
y1  <- exp(xbetas)/(1 + exp(xbetas))

newdata <- as.data.frame(newdata)

# Taking quantiles to get point estimate and confidence intervals ##
quantileValues1 <- apply(X = y1, 
                         MARGIN = 1, 
                         FUN = quantile, 
                         na.rm = T, 
                         probs = c(.025,.5,.975))
plotData <- as.data.frame( t(quantileValues1))

# making the plot: 

plotData$`Type of actor` <- c("Individual",
                              "Business")

plotData <- plotData %>%
  arrange(`Type of actor`)

plotData$x <- c(1, 2)

# pdf("Results/Figures/Coefplot_mod_cmlr.pdf")
ggplot() +
  geom_point(aes(x = x, 
                 y = `50%`,
                 color = `Type of actor`),
             data = plotData,
             size = 3) +
  geom_errorbar(aes(x= x,
                    ymin = `2.5%`,
                    ymax = `97.5%`,
                 color = `Type of actor`),
                data = plotData,
                width = 0) +
  scale_color_manual(values = paste(rep(color_choice[1:2],2))) +
  ggtitle("AMPLIFYING: Annotations in the \nCOMMON MARKET LAW REVIEW by type of litigant") +
  # ylim(c(4,10)) +
  xlim(c(0.8,2.2)) +
  xlab("") +
  ylab("Prob. of an annotation in CMLR") +
     theme(
       plot.title = element_text(size = 18),
       axis.text.x= element_blank(),
        axis.title.y = element_text(size = 16),
        axis.ticks.x = element_blank(),
        # panel.background = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.major.y = element_line(linetype = 2),
        legend.position = "bottom",         
        legend.direction = "horizontal",
        legend.text = element_text(size = 16), 
         #legend.key = element_text( size = 16),
        legend.title = element_text(face = "bold",
                                    size = 16))
  


# dev.off()

plotData.cmlr <- plotData
```


## Figure 9

### Figure 9a

```{r  "figure 9a - press"}
set.seed(24)

# predictions
newdata <- matrix(data = 0, 
                   ncol = mod.press.win %>% coefficients() %>% length, 
                   nrow = 4)

colnames(newdata) <- mod.press.win%>%
  coefficients() %>%
  names()
 
#Common scenario features

#one observation in EU 15
id.sc2 <- grep("observations", colnames(newdata))
newdata[, id.sc2] = 1/15

#Baseline company

id.sc2 <- grep("Inter|2000", colnames(newdata))
newdata[, id.sc2] = 1

# Scenario 3-4: Individuals
id.sc1 <- grep("^individual", colnames(newdata))
newdata[3:4, id.sc1] = 1

# Scenario 2-4: winning
id.sc1 <- grep("win$", colnames(newdata))
newdata[c(2, 4), id.sc1] = 1

#individual winning : scenario 4
id.sc1 <- grep("win:individual", colnames(newdata))[1]
newdata[4, id.sc1] = 1

sim1 <- mvrnorm(n=10000, 
                mu=mod.press.win$coefficients, 
                Sigma = vcov(mod.press.win))

xbetas <- newdata %*% t(sim1)
y1 <- exp(xbetas)/(1+exp(xbetas))

# Taking quantiles to get point estimate and confidence intervals ##
plotData <- apply(X = y1, 
                         MARGIN = 1, 
                         FUN = quantile, 
                         na.rm = T, 
                         probs = c(.025,.5,.975)) %>%
  t() %>%
  as.data.frame()

plotData$x <- c(1, 2, 1.2, 2.2)

plotData$`Winning` <- rep(c(
                            "Lose", "Win"),
                          2)
plotData$`Type of actor` <- c(rep("Business", 2),
                              rep("Individual", 2))


## Making company 

# pdf("Results/Figures/Coefplot_mod_press_release_winning.pdf")
ggplot(plotData) +
  geom_point(aes(x = x, 
                 y = `50%`,
                 color = `Type of actor`),
             size = 3) +
  geom_line(aes(x = x, 
                y = `50%`,
                color =  `Type of actor`),
            plotData[c(1,2),],
            lty = 2) +
  geom_line(aes(x = x, 
                y = `50%`,
                color =  `Type of actor`),
            plotData[c(3,4),],
            lty = 2) +
  geom_errorbar(aes(x= x,
                    ymin = `2.5%`,
                    ymax = `97.5%`,
                    color =  `Type of actor`),
                width = 0) +
  scale_color_manual(values = paste(rep(color_choice,2))) + 
  ggtitle("SPOTLIGHTING: Effect of individual applicants winning \non the Court's decision to issue a PRESS RELEASE") +
  ylim(c(0, 0.4)) +
  xlim(c(0.8,2.2)) +
  xlab("") +
  ylab("Probability of a press release") +
  scale_x_continuous(breaks=c(1.1, 2.1),
                     labels=c("Lose", "Win")) +
  theme(axis.title.y = element_text(size = 16),
        axis.ticks.x = element_blank(),
        axis.text.x = element_text(angle = 45),
        axis.line.x = element_blank(),
        # panel.background = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.major.y = element_line(linetype = 2),
        legend.position = "bottom",         
        legend.direction = "horizontal",
        legend.text = element_text(size = 16), 
        #legend.key = element_text( size = 16),
        legend.title = element_text(face = "bold",
                                    size = 16))

# dev.off()
```


### Figure 9b

```{r "figure 9b - annotations"}

set.seed(24)

# predictions
newdata <- matrix(data = 0, 
                   ncol = mod.ann.win %>%coefficients() %>% length, 
                   nrow = 4)

colnames(newdata) <- mod.ann.win%>%
  coefficients() %>%
  names()
 
#Common scenario features

#In 1990-ies; first iteration before the court; country of origin == italy
id.sc2 <- grep("1990|Italy", colnames(newdata))
newdata[, id.sc2] = 1

#one observation in EU 15
id.sc2 <- grep("observations", colnames(newdata))
newdata[, id.sc2] = 1/15

#Baseline company

id.sc2 <- grep("Inter", colnames(newdata))
newdata[, id.sc2] = 1

# Scenario 3-4: Individuals
id.sc1 <- grep("^individual", colnames(newdata))
newdata[3:4, id.sc1] = 1

# Scenario 2-4: winning

id.sc1 <- grep("win$", colnames(newdata))
newdata[c(2, 4), id.sc1] = 1

#individual winning : scenario 4
id.sc1 <- grep("win:individual", colnames(newdata))[1]
newdata[4, id.sc1] = 1

sim1 <- mvrnorm(n=10000, 
                mu=mod.ann.win$coefficients, 
                Sigma = vcov(mod.ann.win))

xbetas <- newdata %*% t(sim1)
y1 <- exp(xbetas) #/(1+exp(xbetas))

# Taking quantiles to get point estimate and confidence intervals ##
plotData <- apply(X = y1, 
                         MARGIN = 1, 
                         FUN = quantile, 
                         na.rm = T, 
                         probs = c(.025,.5,.975)) %>%
  t() %>%
  as.data.frame()

plotData$x <- c(1, 2, 1.2, 2.2)

plotData$`Winning` <- rep(c(
                            "Lose", "Win"),
                          2)
plotData$`Type of actor` <- c(rep("Business", 2),
                              rep("Individual", 2))


## Making company 

# pdf("Results/Figures/Coefplot_mod_annotation_winning.pdf")
ggplot(plotData) +
  geom_point(aes(x = x, 
                 y = `50%`,
                 color = `Type of actor`),
             size = 3) +
  geom_line(aes(x = x, 
                y = `50%`,
                color =  `Type of actor`),
            plotData[c(1,2),],
            lty = 2) +
  geom_line(aes(x = x, 
                y = `50%`,
                color =  `Type of actor`),
            plotData[c(3,4),],
            lty = 2) +
  geom_errorbar(aes(x= x,
                    ymin = `2.5%`,
                    ymax = `97.5%`,
                    color =  `Type of actor`),
                width = 0) +
  scale_color_manual(values = paste(rep(color_choice,2))) +
   ggtitle("AMPLIFYING: Effect of individual applicants winning \non annotations in LEGAL JOURNALS") +
  #ylim(c(0, 0.22)) +
  xlim(c(0.8,2.2)) +
  xlab("") +
  ylab("Number of annotations") +
  scale_x_continuous(breaks=c(1.1, 2.1),
                     labels=c("Lose", "Win")) +
  theme(
       plot.title = element_text(size = 18),
       axis.title.y = element_text(size = 16),
        axis.ticks.x = element_blank(),
        axis.text.x = element_text(angle = 45),
        axis.line.x = element_blank(),
        # panel.background = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.major.y = element_line(linetype = 2),
        legend.position = "none", # "bottom",         
        legend.direction = "horizontal",
        legend.text = element_text(size = 16), 
        #legend.key = element_text( size = 16),
        legend.title = element_text(face = "bold",
                                    size = 16))

# dev.off()

```

### Figure 9c

```{r "figure 9b - annotations in the CMLR"}

set.seed(24)

# predictions
newdata <- matrix(data = 0, 
                   ncol = mod.cmlr.win %>%coefficients() %>% length, 
                   nrow = 4)

colnames(newdata) <- mod.cmlr.win%>%
  coefficients() %>%
  names()
 
#Common scenario features

#In 1990-ies; first iteration before the court
id.sc2 <- grep("1990", colnames(newdata))
newdata[, id.sc2] = 1

#one observation in EU 15
id.sc2 <- grep("observations", colnames(newdata))
newdata[, id.sc2] = 1/15

#Baseline company

id.sc2 <- grep("Inter", colnames(newdata))
newdata[, id.sc2] = 1

# Scenario 3-4: Individuals
id.sc1 <- grep("^individual", colnames(newdata))
newdata[3:4, id.sc1] = 1

# Scenario 2-4: winning

id.sc1 <- grep("win$", colnames(newdata))
newdata[c(2, 4), id.sc1] = 1

#individual winning : scenario 4
id.sc1 <- grep("win:individual", colnames(newdata))[1]
newdata[4, id.sc1] = 1

sim1 <- mvrnorm(n=10000, 
                mu=mod.cmlr.win$coefficients, 
                Sigma = vcov(mod.cmlr.win))

xbetas <- newdata %*% t(sim1)
y1 <- exp(xbetas)/(1+exp(xbetas))

# Taking quantiles to get point estimate and confidence intervals ##
plotData <- apply(X = y1, 
                         MARGIN = 1, 
                         FUN = quantile, 
                         na.rm = T, 
                         probs = c(.025,.5,.975)) %>%
  t() %>%
  as.data.frame()

plotData$x <- c(1, 2, 1.2, 2.2)

plotData$`Winning` <- rep(c(
                            "Lose", "Win"),
                          2)
plotData$`Type of actor` <- c(rep("Business", 2),
                              rep("Individual", 2))


## Making company 

# pdf("Results/Figures/Coefplot_mod_cmlr_annotation_winning.pdf")
ggplot(plotData) +
  geom_point(aes(x = x, 
                 y = `50%`,
                 color = `Type of actor`),
             size = 3) +
  geom_line(aes(x = x, 
                y = `50%`,
                color =  `Type of actor`),
            plotData[c(1,2),],
            lty = 2) +
  geom_line(aes(x = x, 
                y = `50%`,
                color =  `Type of actor`),
            plotData[c(3,4),],
            lty = 2) +
  geom_errorbar(aes(x= x,
                    ymin = `2.5%`,
                    ymax = `97.5%`,
                    color =  `Type of actor`),
                width = 0) +
  scale_color_manual(values = paste(rep(color_choice,2))) +
   ggtitle("AMPLIFYING: Effect of individual applicants winning \non annotations in the CMLR") +
  ylim(c(0, 0.25)) +
  xlim(c(0.8,2.2)) +
  xlab("") +
  ylab("Probability of annotation") +
  scale_x_continuous(breaks=c(1.1, 2.1),
                     labels=c("Lose", "Win")) +
  theme(
       plot.title = element_text(size = 18),
       axis.title.y = element_text(size = 16),
        axis.ticks.x = element_blank(),
        axis.text.x = element_text(angle = 45),
        axis.line.x = element_blank(),
        # panel.background = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.major.y = element_line(linetype = 2),
        legend.position = "none", #"bottom",         
        legend.direction = "horizontal",
        legend.text = element_text(size = 16), 
        #legend.key = element_text( size = 16),
        legend.title = element_text(face = "bold",
                                    size = 16))

# dev.off()
```


# Appendix 


## Table 5

```{r "table 5 - summary statistics", results="asis"}
df_role$company <- as.numeric(df_role$company == TRUE)
df_role$individual <- as.numeric(df_role$individual == TRUE)
df_role$ngo <- as.numeric(df_role$ngo == TRUE)
df_role$state_institution <- as.numeric(df_role$state_institution == TRUE)
df_role$other <- as.numeric(df_role$other == TRUE)

variables <- c(          
  "written", 
  "n_appearances", "n_lawyers",
  "company", "individual",  "ngo",     
  "state_institution", "other", 
  "joined_case")

df_role_stats <- apply(df_role[, variables], 2, as.numeric )

stargazer(df_role_stats,
          digits = 2,
          title = "Summary statistics of role-level data",
          font.size = "scriptsize",
          summary = T,
          summary.stat = c("min",
                           "p25",
                           "mean",
                           "median",
                           "p75",
                           "max", 
                           "n"),
          label = "tab:summary_role",
          # out = "Results/Tables/summary_statistics_role.tex",
          type = "html")
```


## Table 6: summary statistics (first time period)

```{r "table 6 - summary statistics", results="asis"}
df_app$company <- as.numeric(df_app$company == TRUE)
df_app$individual <- as.numeric(df_app$individual == TRUE)
df_app$ngo <- as.numeric(df_app$ngo == TRUE)
df_app$state_institution <- as.numeric(df_app$state_institution == TRUE)
df_app$other <- as.numeric(df_app$other == TRUE)

df_app$net_lawyers <- (df_app$n_lawyers - df_app$n_lawyers_def)
df_app$net_appearances <- (df_app$n_appearances - df_app$n_appearances_def)
df_app$net_support <- (df_app$govobspl - df_app$govobsdef)

variables <- c(
  "win",
  "ind_rights",
  "company", "individual",  "ngo",     
  "state_institution", "other", 
  "net_support",
  "net_lawyers",
  "net_appearances",
  "challenge")

df_app_stats <- apply(df_app[, variables], 2, as.numeric )

stargazer(df_app_stats,
          digits = 2,
          title = "Summary statistics of applicant-level data (1961-97)",
          font.size = "scriptsize",
          summary = T,
          summary.stat = c("min",
                           "p25",
                           "mean",
                           "median",
                           "p75",
                           "max", 
                           "n"),
          label = "tab:summary_app",
          # out = "Results/Tables/summary_statistics_applicant.tex"
          type = "html")
```


## Table 7: summary statistis (second time period)

```{r "table 7 - summary statistics"}
df2_app$company <- as.numeric(df2_app$company == TRUE)
df2_app$individual <- as.numeric(df2_app$individual == TRUE)
df2_app$ngo <- as.numeric(df2_app$ngo == TRUE)
df2_app$state_institution <- as.numeric(df2_app$state_institution == TRUE)
df2_app$other <- as.numeric(df2_app$other == TRUE)

df2_app$net_lawyers <- (df2_app$n_lawyers - df2_app$n_lawyers_def)
df2_app$net_appearances <- (df2_app$n_appearances - df2_app$n_appearances_def)
df2_app$net_support <- (df2_app$govobspl - df2_app$govobsdef)

variables <- c(
  "win",
  "ind_rights",
  "company", "individual",  "ngo",     
  "state_institution", "other", 
  "net_support",
  "net_lawyers",
  "net_appearances",
  "challenge")

df2_app_stats <- apply(df2_app[, variables], 2, as.numeric )

```

```{r "table 7 - summary statistics - table", results="asis"}

stargazer(df_app_stats,
          digits = 2,
          title = "Summary statistics of applicant-level data (1995-08)",
          font.size = "scriptsize",
          summary = T,
          summary.stat = c("min",
                           "p25",
                           "mean",
                           "median",
                           "p75",
                           "max", 
                           "n"),
          label = "tab:summary_app2",
          # out = "Results/Tables/summary_statistics_applicant2.tex"
          type = "html")
```

## Table 8

```{r "table 8 - summary statistics"}
df_case$large <- as.numeric(df_case$chamber_size == "large")
df_case$medium <- as.numeric(df_case$chamber_size == "medium")
df_case$small <- as.numeric(df_case$chamber_size == "small")

variables <- c(        
  "company_applicant", "individual_applicant",  "ngo_applicant",     
  "state_institution_applicant", "other_applicant", "written_applicant", 
  "n_appearances_applicant", "n_lawyers_applicant",
  "win",
  "ind_rights",
  "press_release","n_annotations", "n_annotations_CMLR",
  "small", "medium", "large",
  "n_iteration", "observations_prop_tot",
  "company_defendant", "individual_defendant",
  "ngo_defendant", "state_institution_defendant", "other_defendant",   
  "written_defendant", "n_appearances_defendant",  "n_lawyers_defendant")

df_stats <- apply(df_case[, variables], 2, as.numeric )

```

```{r "table 8 - summary statistics - table", results="asis"}
stargazer(df_stats,
          digits = 2,
          title = "Summary statistics of case-level data",
          font.size = "scriptsize",
          summary = T,
          summary.stat = c("min",
                           "p25",
                           "mean",
                           "median",
                           "p75",
                           "max", 
                           "n"),
          label = "tab:summary_case",
          # out = "Results/Tables/summary_statistics_case.tex",
          type = "html")
```

## Table 9

```{r "table 9a - win 1"}
#Carrubba and hankla data##
mod.win.ch <- plm(win ~ 
                    individual +
                    ngo +
                    state_institution +
                    other +
                    I(govobspl - govobsdef) +
                    # I(n_iteration == 1) +
                   # log(n_iteration) +
                    challenge +
                    individual_def +
                    ngo_def +
                    state_institution_def +
                    other_def +
                    I(n_lawyers - n_lawyers_def) +
                    I(n_appearances - n_appearances_def),
                  effect = "individual",
                  index = "n_iteration",
              #    family = "binomial",
                  weights = 1/n_issues,
                  # na.action = "na.exclude",
                  df_app)
# summary(mod.win.ch)

#Custered errors
mod.win.ch.se <- coef_test(mod.win.ch, 
                           vcovCR(mod.win.ch,
                                  cluster = df_app$celex,
                                  type = "CR1p"),
                           test = "naive-t")

```

```{r "table 9b"}
mod.win.ind.ch <- plm(win ~ 
                        ind_rights * individual +
                        ngo +
                        state_institution +
                        other +
                        I(govobspl - govobsdef) +
                        # I(n_iteration == 1) +
                      #  log(n_iteration) +
                        challenge +
                        individual_def +
                        ngo_def +
                        state_institution_def +
                        other_def +
                        I(n_lawyers - n_lawyers_def) +
                        I(n_appearances - n_appearances_def)
                      ,
                      weights = 1/n_issues,
                      index = "n_iteration",
                      effect = "individual",
                      df_app)

# summary(mod.win.ind.ch)


# Compute clustered standard errors, clustering around 'celex'

mod.win.ind.ch.se <- coef_test(mod.win.ind.ch, 
                               vcovCR(mod.win.ind.ch,
                                      cluster = df_app$celex,
                                      type = "CR1p"),
                               test = "naive-t")


```

```{r "table 9c"}
mod.win.ln <- plm(win ~ 
                        individual +
                        ngo +
                        state_institution +
                        other +
                        I(govobspl - govobsdef) +
                        # I(n_iteration == 1) +
                        #  log(n_iteration) +
                        challenge +
                        individual_def +
                        ngo_def +
                        state_institution_def +
                        other_def +
                        I(n_lawyers - n_lawyers_def) +
                        I(n_appearances - n_appearances_def)
                      ,
                      index = "n_iteration",
                      effect = "individual",
                      weights = 1/n_issues,
                      df2_app %>%
                       mutate(
                         individual = as.numeric(individual),
                         ngo = as.numeric(ngo),
                         state_institution = as.numeric(state_institution),
                         other = as.numeric(other)
                       ))

# summary(mod.win.ln)

#Custered errors
mod.win.ln.se <- coef_test(mod.win.ln, 
                           vcovCR(mod.win.ln,
                                  cluster = df2_app$celex,
                                  type = "CR1p"),
                           test = "naive-t")

```

```{r "table 9d"}

mod.win.ind.ln <- plm(win ~ 
                        ind_rights * individual +
                        ngo +
                        state_institution +
                        other +
                        I(govobspl - govobsdef) +
                        # I(n_iteration == 1) +
                        #  log(n_iteration) +
                        challenge +
                        individual_def +
                        ngo_def +
                        state_institution_def +
                        other_def +
                        I(n_lawyers - n_lawyers_def) +
                        I(n_appearances - n_appearances_def)
                      ,
                      index = "n_iteration",
                      effect = "individual",
                     weights = 1/n_issues,
                      df2_app %>%
                       mutate(
                         individual = as.numeric(individual),
                         ngo = as.numeric(ngo),
                         state_institution = as.numeric(state_institution),
                         other = as.numeric(other)
                       ))

# summary(mod.win.ind.ln)

#Custered errors
mod.win.ind.ln.se <- coef_test(mod.win.ind.ln, 
                               vcovCR(mod.win.ind.ln,
                                      cluster = df2_app$celex,
                                      type = "CR1p"),
                               test = "naive-t")

```


```{r "table 9 - make the table - separate models for two time period", type = "asis"}
#Separate data sets##

variables <- c("Individual rights",
               "Individual (ref. business)",
               "Interest group (ref. business)",
               "State institution (ref. business)",
               "Other (ref. business)",
               "Net support from MS observations",
#               "First time an EU law is applied",
               "The validity of an EU law is in question",
               # "Support from EU Commission",
               "Defendant is ... an individual (ref. business)",
               "... interest group (ref. business)",
               "... state institution (ref. business)",
               "... other type of actor (ref. business)",
               "Difference in legal team size",
               "Difference in lawyer experience",
               "Individual * individual rights (H1)")

stargazer(mod.win.ch, mod.win.ind.ch, 
          mod.win.ln, mod.win.ind.ln,
          se = list(mod.win.ch.se$SE,
                    mod.win.ind.ch.se$SE,
                    mod.win.ln.se$SE,
                    mod.win.ind.ln.se$SE),
          covariate.labels = variables,
          column.labels = c(period.ch, period.ch, 
                            period.ln, period.ln),
          dep.var.labels = c("Wins the case"),
          # column.separate = c(2,2),
          model.numbers = FALSE,
          model.names = TRUE,
          font.size = "scriptsize",
          omit.stat = "f",
          title = "Variation in the likelihood of winning among applicants accross types of litigants.",
          omit = "decade",
          label = "tab:win_separate",
          add.lines = list(c("Fixed effects for iteration of interpretation", "Yes", "Yes", "Yes", "Yes")),
          # out = "Results/Tables/table_win_separate.tex",
          type = "html")

```


## Table 10


```{r "table 10 - estimate the models a-d"}
##Common Market Law Review: effect of chamber size
mod.chamber.cmlr <- glm(n_annotations_CMLR ~
                            chamber_size +
                            individual +
                            ngo +
                            state_institution +
                            other +
                          individual +
                          ngo + 
                          state_institution +
                          other +
                            # individual +
                            # ngo +
                            # state_institution +
                            # other +
                            # obs_applicant +
                            # obs_defendant +
                            log(n_lawyers_applicant + 1) +
                            log(n_lawyers_defendant + 1) +
                            log(n_appearances_applicant + 1) +
                            log(n_appearances_defendant + 1) +
                            log(n_iteration) +
                            observations_prop_tot +
                          as.factor(decade_lodged)
                          ,
                          df_case %>%
                            mutate(
                              n_annotations_CMLR = as.numeric(n_annotations_CMLR>0),
                              company = as.numeric(company),
                              chamber_size = as.character(chamber_size),
                              chamber_size = if_else(chamber_size == "small",
                                                     "1. small",
                                                     if_else(chamber_size == "medium",
                                                             "2. medium",
                                                             "3. large"))
                            ),
                          family = "binomial"
)

# summary(mod.chamber.cmlr)

##Common Market Law Review: effect of press release
mod.press.cmlr <- glm(n_annotations_CMLR ~
                              press_release +
                              individual +
                              ngo +
                              state_institution +
                              other +
                              individual +
                              ngo + 
                              state_institution +
                              other +
                              # individual +
                              # ngo +
                              # state_institution +
                              # other +
                              # obs_applicant +
                              # obs_defendant +
                              log(n_lawyers_applicant + 1) +
                              log(n_lawyers_defendant + 1) +
                              log(n_appearances_applicant + 1) +
                              log(n_appearances_defendant + 1) +
                              log(n_iteration) +
                              observations_prop_tot +
                            # (1|decade_lodged)
                            as.factor(decade_lodged)
                            ,
                            df_case %>%
                              mutate(
                                n_annotations_CMLR = as.numeric(n_annotations_CMLR>0),
                                company = as.numeric(company),
                                chamber_size = as.character(chamber_size),
                                chamber_size = if_else(chamber_size == "small",
                                                       "1. small",
                                                       if_else(chamber_size == "medium",
                                                               "2. medium",
                                                               "3. large"))
                              ),
                            family = "binomial"
)

# summary(mod.press.cmlr)


##All law reviews: effect of chamber size
mod.chamber.ann <- glm.nb(n_annotations ~
                            chamber_size +
                            individual +
                            ngo +
                            state_institution +
                            other +
                          individual +
                          ngo + 
                          state_institution +
                          other +
                            # individual +
                            # ngo +
                            # state_institution +
                            # other +
                            # obs_applicant +
                            # obs_defendant +
                            log(n_lawyers_applicant + 1) +
                            log(n_lawyers_defendant + 1) +
                            log(n_appearances_applicant + 1) +
                            log(n_appearances_defendant + 1) +
                            log(n_iteration) +
                            observations_prop_tot +
                          as.factor(decade_lodged) +
                          as.factor(origin)
                          ,
                          df_case %>%
                            mutate(
                              n_annotations_CMLR = as.numeric(n_annotations_CMLR>0),
                              company = as.numeric(company),
                              chamber_size = as.character(chamber_size),
                              chamber_size = if_else(chamber_size == "small",
                                                     "1. small",
                                                     if_else(chamber_size == "medium",
                                                             "2. medium",
                                                             "3. large"))
                            )
)

# summary(mod.chamber.ann)

##All law reviews: effect of press release
mod.press.ann <- glm.nb(n_annotations ~
                              press_release +
                              individual +
                              ngo +
                              state_institution +
                              other +
                              individual +
                              ngo + 
                              state_institution +
                              other +
                              # individual +
                              # ngo +
                              # state_institution +
                              # other +
                              # obs_applicant +
                              # obs_defendant +
                              log(n_lawyers_applicant + 1) +
                              log(n_lawyers_defendant + 1) +
                              log(n_appearances_applicant + 1) +
                              log(n_appearances_defendant + 1) +
                              log(n_iteration) +
                              observations_prop_tot +
                            # (1|decade_lodged)
                            as.factor(decade_lodged) +
                          + as.factor(origin)
                            ,
                            df_case %>%
                              mutate(
                                n_annotations_CMLR = as.numeric(n_annotations_CMLR>0),
                                company = as.numeric(company),
                                chamber_size = as.character(chamber_size),
                                chamber_size = if_else(chamber_size == "small",
                                                       "1. small",
                                                       if_else(chamber_size == "medium",
                                                               "2. medium",
                                                               "3. large"))
                              )
)

```


```{r "table 10", results="asis"}
variables.attention <- c(
  "Medium chamber (ref. small)",
  "Large chamber (ref. small)",
  "Press release",
  "Applicant is... an individual (ref. business)",
                         "... interest group (ref. business)",
                         "... state institution (ref. business)",
                         "... other type of actor (ref. business)",
                         "Size of applicant's legal team (log + 1)",
                         "Size of defendant's legal team (log + 1)",
                         "Experience of applicant's lawyer (log + 1)",
                         "Experience of defendant's lawyer (log + 1)",
                         "Times an EU law is applied (log)",
                         "Proportion of MS observations")
 
##Table for main text##
stargazer(mod.chamber.cmlr, mod.press.cmlr, mod.chamber.ann, mod.press.ann,
          covariate.labels = variables.attention,
          # column.labels = c("1961-2016",
          #                   "1995-2016",
          #                   "1961-2016",
          #                   "1961-2016"),          
          # dep.var.labels = c( "CMLR", "CMLR", "All", "All"),
          dep.var.labels.include = TRUE,
          model.numbers = FALSE,
          model.names = TRUE,
          dep.var.caption = c("\\emph{Dependent variable: Amplifying (academic attention)}"),
          add.lines = list(
                           c("Decade fixed effects", "Yes", "Yes", "Yes", "Yes"),
                           c("Country of origin fixed effects", "No", "No", "Yes", "Yes")),
          ord.intercepts = TRUE,
          title = "Spotlighting and amplifying: Judicial and academic issue attention depend on the type of litigants involved.",
          omit = "decade|EUsize|origin",
          keep.stat = "n",
          font.size = "tiny",
          label = "tab:spot_amp",
          # out = "Results/Tables/table_spotlighting_amplifying.tex",
          type = "html"
          )

```

